package com.aaa.service.impl.mht;

import com.aaa.entity.MyPage;
import com.aaa.entity.mht.MhtRecord;
import com.aaa.mapper.mht.MhtRecordMapper;
import com.aaa.service.mht.MhtRecordService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class MhtRecordServiceImpl implements MhtRecordService {
    @Autowired
    private MhtRecordMapper mhtRecordMapper;
    /**
     * 检测该电话号码是否已经做题
     * @return
     * @param mhtRecord
     */
    @Override
    public MhtRecord checkUserRecord(MhtRecord mhtRecord) {
        MhtRecord mhtRecord1 = mhtRecordMapper.selectOne(mhtRecord);
        return mhtRecord1;
    }

    /**
     * 添加用户的记录
     * @param mhtRecord
     * @return
     */
    @Override
    public int insertUserRecord(MhtRecord mhtRecord) {
        mhtRecord.setCreatetime(new Date());
        int insert = mhtRecordMapper.insert(mhtRecord);
        Integer id = mhtRecord.getId();
        return id;
    }

    /**
     * 查询所有的测试记录
     * @param myPage
     * @param mhtRecord
     * @return
     */
    @Override
    public PageInfo findAllRecord(MyPage myPage, MhtRecord mhtRecord) {
        PageHelper.startPage(myPage.getPage(),myPage.getLimit());
        List<MhtRecord> mhtRecordList = mhtRecordMapper.findAllRecord(mhtRecord);
        PageInfo pageInfo = new PageInfo(mhtRecordList);
        return pageInfo;
    }
    /**
     * 查询测试人的答题信息
     * @param myPage
     * @param id
     * @return
     */
    @Override
    public PageInfo findRecordAnswer(MyPage myPage, Integer id) {
        PageHelper.startPage(myPage.getPage(),myPage.getLimit());
        List<Map<String,Object>> detail = mhtRecordMapper.getdetail(id);
        PageInfo pageInfo = new PageInfo(detail);
        return pageInfo;
    }
}
